
package com.ywjg.serviceimp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.ywjg.dao.CheckRapairDao;
import com.ywjg.dao.RapairCommentDao;
import com.ywjg.dao.RapairToRapairTypeDao;
import com.ywjg.model.RapairComment;
import com.ywjg.service.IRapairCommentService;
import com.ywjg.utils.Utils;

@Service
public class RapairCommentService implements IRapairCommentService {
	@Resource
	RapairToRapairTypeDao rapairToRapairTypeDao;
	@Resource
	CheckRapairDao checkRapairDao;
	@Resource
	RapairCommentDao rapairCommentDao;
   
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#addOneRapairComment(com.ywjg.model.RapairComment)
	 */
	public RapairComment addOneRapairComment(RapairComment rapairComment) {

		return rapairCommentDao.save(rapairComment);
	}
	
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#getById(int)
	 */
	public RapairComment getById(int id) {

		return rapairCommentDao.findOne(id);
	}
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#upDateRapairComment(com.ywjg.model.RapairComment)
	 */
	public RapairComment upDateRapairComment(RapairComment rapairComment) {
		RapairComment findRapairComment = rapairCommentDao.findOne(rapairComment.getId());
        Utils.copyPropertiesIgnoreNull(rapairComment, findRapairComment);
		return rapairCommentDao.save(findRapairComment);
	}
	
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#rapairGetRapairComment(java.lang.Integer)
	 */
	public List<RapairComment> rapairGetRapairComment(Integer id) {
		
		Pageable pageable = new PageRequest(0, 100, new Sort(Direction.DESC,"timestamp"));
		
		return rapairCommentDao.findByRapairIdAndUserIsComment(id,1,pageable);
	}
	
	
   /* (non-Javadoc)
 * @see com.ywjg.serviceimp.IRapairCommentService#userGetRapairComment(java.lang.Integer)
 */
public List<RapairComment> userGetRapairComment(Integer id) {
		
		Pageable pageable = new PageRequest(0, 100, new Sort(Direction.DESC,"timestamp"));
		
		return rapairCommentDao.findByUserIdAndRapairIsComment(id, 1, pageable);
	}
   
   
   /* (non-Javadoc)
 * @see com.ywjg.serviceimp.IRapairCommentService#completeRapairPrice(com.ywjg.model.RapairComment)
 */
public RapairComment completeRapairPrice(RapairComment rapairComment) {
	   
	   RapairComment findOne = rapairCommentDao.findOne(rapairComment.getId());
	   Utils.copyPropertiesIgnoreNull(rapairComment, findOne);
	   
	  return rapairCommentDao.save(findOne);
		
		
	}
   
    /* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#rapairGetOrder(java.lang.Integer)
	 */
    public List<RapairComment> rapairGetOrder(Integer id) {
    	Pageable pageable = new PageRequest(0, 100, Direction.DESC, "timestamp");
    	List<RapairComment> findByRapairId = rapairCommentDao.findByRapairId(id, pageable);
		return findByRapairId;
    }
    
    /* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IRapairCommentService#userGetRapairOrder(java.lang.Integer)
	 */
    public List<RapairComment> userGetRapairOrder(Integer id) {
    	Pageable pageable = new PageRequest(0, 100, Direction.DESC, "timestamp");
    	List<RapairComment> findByRapairId = rapairCommentDao.findByUserId(id, pageable);
		return findByRapairId;
    }
	

}